package com.zhaolaobao.redis.queue.config;

import com.zhaolaobao.redis.queue.core.RedisDelayQueueListen;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName RedisDelayQueueInit
 * @Description //
 * @Author WHX
 * @Date 2021/10/29 13:10
 **/
@Component
@Slf4j
public class RedisDelayQueueInit implements CommandLineRunner {
    @Resource
    private RedisDelayQueueListen redisDelayQueueListen;

    /**
     * Callback used to run the bean.
     *
     * @param args incoming main method arguments
     * @throws Exception on error
     */
    @Override
    public void run(String... args) {
        RedisDelayQueueBeanProcessor.methodCache.forEach((queueName, methodQuote) -> {
            new Thread(() -> {
                redisDelayQueueListen.listen(queueName, methodQuote);
            }, queueName).start();
        });
    }
}